<?php

namespace app\common\model;

use houdunwang\arr\Arr;
use think\Loader;
use think\Model;

class Category extends Model {
    protected $pk    = 'cate_id';
    protected $table = 'blog_cate';

    public function store($data) {
        //1.执行验证
        //2.添加功能
        $ret = $this->validate(true)->save($data);
        if (false === $ret) {
            return ['valid' => 0, 'msg' => $this->getError()];
        } else {
            return ['valid' => 1, 'msg' => '添加成功！'];
        }
    }

    public function getTreeAll() {
        $data = self::all();
        return Arr::tree($data,'cate_name','cate_id','cate_pid');
    }

}
